<template>
	<view class="page-container">
		<view class="header">
			<view class="header-content">
				<text class="title">球队列表</text>
				<text class="subtitle">共 {{ tournamentTeamsList.length }} 支球队</text>
			</view>
			<view class="header-decoration"></view>
		</view>

		<view class="tabs-container">
			<view v-for="(tab, index) in tabs" :key="index" class="tab-item" :class="{ active: currentTab === index }" @tap="switchTab(index)">
				<text class="tab-text">{{ tab.name }}</text>
				<text class="tab-count" v-if="tab.count !== undefined">({{ tab.count }})</text>
			</view>
		</view>

		<view class="teams-container">
			<view v-if="currentTab === 0">
				<view @click="goDetail(team)" v-for="team in tournamentTeamsList" :key="team.id" class="team-card" hover-class="team-card-hover">
					<view class="team-left">
						<image :src="config.baseUrl + team.emblemUrl" class="team-logo" />
						<view class="team-badge"></view>
					</view>
					<view class="team-info">
						<text class="team-name">{{ team.teamName }}</text>
						<view class="team-region-wrapper">
							<text class="region-label">所属地区</text>
							<text class="team-region">{{ team.region }}</text>
						</view>
					</view>
					<view class="team-arrow">
						<text class="arrow-icon">›</text>
					</view>
				</view>
			</view>

			<view v-if="currentTab === 1">
				<view @click="goDetail(team, 1)" v-for="team in myTeamList" :key="team.id" class="team-card" hover-class="team-card-hover">
					<view class="team-left">
						<image :src="config.baseUrl + team.emblemUrl" class="team-logo" />
						<view class="team-badge"></view>
					</view>
					<view class="team-info">
						<text class="team-name">{{ team.teamName }}</text>
						<view class="team-region-wrapper">
							<text class="region-label">所属地区</text>
							<text class="team-region">{{ team.region }}</text>
						</view>
					</view>
					<view class="team-arrow">
						<text class="arrow-icon">›</text>
					</view>
				</view>
			</view>

			<view v-if="currentTab === 2">
				<view @click="goDetail(team, 1)" v-for="team in joinTeamList" :key="team.id" class="team-card" hover-class="team-card-hover">
					<view class="team-left">
						<image :src="config.baseUrl + team.emblemUrl" class="team-logo" />
						<view class="team-badge"></view>
					</view>
					<view class="team-info">
						<text class="team-name">{{ team.teamName }}</text>
						<view class="team-region-wrapper">
							<text class="region-label">所属地区</text>
							<text class="team-region">{{ team.region }}</text>
						</view>
					</view>
					<view class="team-arrow">
						<text class="arrow-icon">›</text>
					</view>
				</view>
				<!-- <button class="join-team-btn" @tap="joinTeam">加入球队</button> -->
			</view>
		</view>

		<view class="floating-btn" @tap="createTeam">
			<text class="plus-icon">+</text>
			<text class="btn-text">创建球队</text>
		</view>
	</view>
</template>

<script>
import { getTournamentTeamsList, getMyTeam } from "@/api/system/qiu";
import config from "@/config.js";
export default {
	data() {
		return {
			tournamentTeamsList: [],
			myTeamList: [],
			joinTeamList: [],
			config,
			currentTab: 0,
			tabs: [
				{ name: "全部球队", count: 0 },
				{ name: "我的球队", count: 0 },
				{ name: "已加入的", count: 0 }
			]
		};
	},
	onShow() {
		this.getTournamentTeamsList();
		this.getMyTeam();
	},
	methods: {
		async getTournamentTeamsList() {
			const res = await getTournamentTeamsList({
				pageNum: 1,
				pageSize: 1010
			});
			this.tournamentTeamsList = res.data.records;
			this.tabs[0].count = this.tournamentTeamsList.length;
			this.joinTeamList = this.tournamentTeamsList.filter((item) => item.status == 1);
			this.tabs[2].count = this.joinTeamList.length;
		},
		async getMyTeam() {
			const res = await getTournamentTeamsList({
				pageNum: 1,
				pageSize: 1010,
				type: 1
			});
			this.myTeamList = res.data.records;
			this.tabs[1].count = this.myTeamList.length;
		},
		async switchTab(index) {
			this.currentTab = index;
			if (index === 1) {
				this.getMyTeam();
			}
		},
		createTeam() {
			// 跳转到创建球队页面
			uni.navigateTo({
				url: "/pages/createTeams/createTeams"
			});
		},
		joinTeam() {
			// 跳转到加入球队页面
			uni.navigateTo({
				url: "/pages/qiu/join-team"
			});
		},

		goDetail(item, type) {
			console.log(item);
			uni.setStorageSync("teamInfo", item);
			if (type) {
				uni.navigateTo({
					url: "/pages/teamsDetail/teamsDetail?type=" + type
				});
			} else {
				uni.navigateTo({
					url: "/pages/teamsDetail/teamsDetail?type=" + 0
				});
			}
		}
	}
};
</script>

<style>
.page-container {
	min-height: 100vh;
	background: linear-gradient(to bottom, #f0f2f5, #e6e9f0);
	padding-bottom: 40rpx;
}

.header {
	position: relative;
	padding: 40rpx 30rpx 60rpx;
	background: linear-gradient(135deg, #2df926, #2a5298);
	color: #fff;
	border-bottom-left-radius: 40rpx;
	border-bottom-right-radius: 40rpx;
	box-shadow: 0 4rpx 20rpx rgba(30, 60, 114, 0.2);
}

.header-content {
	position: relative;
	z-index: 2;
}

.header-decoration {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	height: 120rpx;
	background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 25%, transparent 25%), linear-gradient(-45deg, rgba(255, 255, 255, 0.1) 25%, transparent 25%);
	background-size: 40rpx 40rpx;
	opacity: 0.3;
}

.title {
	font-size: 44rpx;
	font-weight: bold;
	display: block;
	margin-bottom: 16rpx;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
}

.subtitle {
	font-size: 28rpx;
	opacity: 0.9;
	letter-spacing: 2rpx;
}

.tabs-container {
	display: flex;
	background: #fff;
	padding: 4rpx 20rpx;
	margin: -20rpx 20rpx 20rpx;
	border-radius: 16rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04);
	position: relative;
	z-index: 10;
}

.tab-item {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20rpx 0;
	position: relative;
	transition: all 0.3s ease;
}

.tab-item.active {
	color: #2a5298;
}

.tab-item.active::after {
	content: "";
	position: absolute;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	width: 40rpx;
	height: 6rpx;
	background: #2a5298;
	border-radius: 6rpx;
}

.tab-text {
	font-size: 28rpx;
	font-weight: 500;
}

.tab-count {
	font-size: 24rpx;
	margin-left: 6rpx;
	color: #999;
}

.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 80rpx 0;
}

.empty-image {
	width: 240rpx;
	height: 240rpx;
	margin-bottom: 30rpx;
	opacity: 0.8;
}

.empty-text {
	font-size: 28rpx;
	color: #999;
	margin-bottom: 40rpx;
}

.create-team-btn,
.join-team-btn {
	width: 240rpx;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	background: linear-gradient(135deg, #1e3c72, #2a5298);
	color: #fff;
	border-radius: 40rpx;
	font-size: 28rpx;
	font-weight: 500;
	box-shadow: 0 4rpx 12rpx rgba(42, 82, 152, 0.3);
}

.teams-container {
	padding: 0 20rpx 30rpx;
}

.team-card {
	background-color: #ffffff;
	border-radius: 20rpx;
	padding: 28rpx;
	margin-bottom: 24rpx;
	display: flex;
	align-items: center;
	box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
	transition: all 0.3s ease;
	position: relative;
	overflow: hidden;
}

.team-card-hover {
	transform: translateX(10rpx);
	background-color: #f8faff;
}

.team-card::after {
	content: "";
	position: absolute;
	left: 0;
	top: 0;
	width: 8rpx;
	height: 100%;
	background: linear-gradient(135deg, #1e3c72, #2a5298);
	border-radius: 4rpx;
}

.team-left {
	position: relative;
	margin-right: 28rpx;
}

.team-logo {
	width: 130rpx;
	height: 130rpx;
	border-radius: 50%;
	border: 4rpx solid #fff;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
	transition: transform 0.3s ease;
}

.team-badge {
	position: absolute;
	right: -6rpx;
	bottom: -6rpx;
	width: 24rpx;
	height: 24rpx;
	background: #4caf50;
	border: 3rpx solid #fff;
	border-radius: 50%;
}

.team-info {
	flex: 1;
	padding-right: 20rpx;
}

.team-name {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 16rpx;
}

.team-region-wrapper {
	display: flex;
	align-items: center;
	gap: 12rpx;
}

.region-label {
	font-size: 26rpx;
	color: #666;
	background: #f5f5f5;
	padding: 4rpx 12rpx;
	border-radius: 6rpx;
}

.team-region {
	font-size: 26rpx;
	color: #2a5298;
	background-color: #f0f4ff;
	padding: 4rpx 20rpx;
	border-radius: 20rpx;
	border: 1rpx solid rgba(42, 82, 152, 0.1);
}

.team-arrow {
	width: 60rpx;
	height: 60rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.arrow-icon {
	font-size: 40rpx;
	color: #999;
	font-weight: 300;
}

.floating-btn {
	position: fixed;
	right: 40rpx;
	bottom: 120rpx;
	display: flex;
	align-items: center;
	background: #32b847;
	padding: 20rpx 40rpx;
	border-radius: 50rpx;
	box-shadow: 0 4rpx 20rpx rgba(50, 184, 71, 0.4);
	z-index: 100;
}

.plus-icon {
	font-size: 40rpx;
	color: #fff;
	margin-right: 10rpx;
}

.btn-text {
	color: #fff;
	font-size: 28rpx;
	font-weight: 500;
}

/* 删除原来的 create-team-btn 样式 */
.create-team-btn {
	display: none;
}
</style>
